home *** CD-ROM | disk | FTP | other *** search
/ Gekkan Dennou Club 147 / Gekkan Dennou Club - 2000.8 Vol. 147 (Japan).7z / Gekkan Dennou Club - 2000.8 Vol. 147 (Japan) (Track 1).bin / games / ippon / source.lzh / player.c < prev    next >
C/C++ Source or Header  |  2000-07-07  |  10KB  |  401 lines

  1. /* player.c */
  2.  
  3. #include <sys/iocs.h>
  4. #include <xsp2lib.h>
  5.  
  6. #include "main.h"
  7. #include "player.h"
  8. #include "shot.h"
  9. #include "eshot.h"
  10. #include "effect.h"
  11. #include "txfont.h"
  12. #include "sound.h"
  13.  
  14. #define PLAYER_BANK1    8    /* 少し傾きパターンへ移行するまでの値 */
  15. #define PLAYER_BANK2    12    /* 一番傾きパターンへ以下同文 */
  16.  
  17. #define PLAYER_SPEED    15    /* 自機の速度 */
  18. #define PLAYER_PALET        0x0500    /* 自機のパレット */
  19. #define PLAYER_PALET_FLASH    0x0D00
  20.  
  21. #define PLAYER_START_X    144    /* 自機出現時の座標 */
  22. #define PLAYER_START_Y    (256+32)
  23.  
  24. #define PLAYER_MINX        (16+8)    /* X 座標最小値 */
  25. #define PLAYER_MAXX        (16+255-8)
  26. #define PLAYER_MINY        (16+16)        /* Y 座標最小値 */
  27. #define PLAYER_MAXY        (16+255-12)
  28.  
  29. #define    TIME_MUTEKI    150    /* 登場時の無敵時間 */
  30.  
  31. enum {
  32.     PLAYER_PT_RIGHT2 = 0,    /* 自機が一番右に傾いている時のパターン */
  33.     PLAYER_PT_RIGHT1,    /*  〃 少し右に     〃      */
  34.     PLAYER_PT_CENTER,    /*  〃 正面を向いている時のパターン */
  35.     PLAYER_PT_LEFT1,    /* 自機が少し右に傾いている時のパターン */
  36.     PLAYER_PT_LEFT2        /*  〃 一番右に     〃      */
  37. };
  38.  
  39.  
  40.  
  41. /* 残機を表示 */
  42. void DispRest (void)
  43. {
  44.     short h;
  45.  
  46. #define REST_DISP_X    2
  47. #define REST_DISP_Y    1
  48.     TxfontCursor (REST_DISP_X, REST_DISP_Y);
  49.     for (h = 0; h < 10; h++) {
  50.         if (h < player->rest - 1)
  51.             TxfontPutchar ('i');    /* 'i' に自機のマークが割り当てられてます */
  52.         else
  53.             TxfontPutchar (' ');
  54.     };
  55. }
  56.  
  57.  
  58.  
  59. /* ゲーム開始時に呼ばれる */
  60. void PlayerInit (void)
  61. {
  62. }
  63.  
  64.  
  65.  
  66. /* プレイヤー出現時に呼ばれる */
  67. void PlayerAlloc (void)
  68. {
  69.     player->lx = PLAYER_START_X * 65536;
  70.     player->ly = PLAYER_START_Y * 65536;
  71.     player->status = PLAYER_STATUS_APPEAR;    /* 出現状態へ */
  72.     player->counter = 0;
  73.     player->muteki = TIME_MUTEKI;
  74.     player->flash = 0;
  75.     player->game_over = GAME_PLAY;
  76.  
  77.     /* コア関連 */
  78.     player->core_info = PALET_CORE_BLUE | PRIORITY_PLAYER;
  79.     player->core_pt = sp_core + 1;
  80. }
  81.  
  82.  
  83.  
  84. /* 自機が生きている時の移動処理 */
  85. static void PlayerMoveAlive (void)
  86. {
  87.     int j;            /* ジョイスティックの入力 */
  88.  
  89.     j = _iocs_joyget (0);    /* ジョイスティック0番 */
  90.  
  91. #if    0
  92.     /* [A] ボタンが押されたか? */
  93.     if ((j & 0b00100000) == 0)
  94.         player->game_over = GAME_ABORT;        /* ゲームオーバーに */
  95. #endif
  96.  
  97.     /* [B] ボタンが押されたか? */
  98.     if ((j & 0b1000000) == 0)
  99.         ShotAlloc ();
  100.  
  101.     /* 自機の上下移動処理 */
  102.     switch (j & 0b0011) {
  103.     case 0b0010:        /* 上 */
  104.         if (player->ly >> 16 > PLAYER_MINY)
  105.             player->ly += xytable[PLAYER_SPEED][192].y;
  106.         break;
  107.     case 0b0001:        /* 下 */
  108.         if (player->ly >> 16 < PLAYER_MAXY)
  109.             player->ly += xytable[PLAYER_SPEED][64].y;
  110.         break;
  111.     default:        /* それ以外 */
  112.         break;
  113.     }
  114.  
  115.     /* 自機の左右移動処理+左右傾き処理 */
  116.     switch (j & 0b1100) {
  117.     case 0b1000:        /* 左 */
  118.         if (player->lx >> 16 > PLAYER_MINX)
  119.             player->lx += xytable[PLAYER_SPEED][128].x;
  120.         if (player->bank > 0) {
  121.             player->bank = 0;
  122.         } else {
  123.             if (player->bank > -PLAYER_BANK2)
  124.                 player->bank--;
  125.         }
  126.         break;
  127.  
  128.     case 0b0100:        /* 右 */
  129.         if (player->lx >> 16 < PLAYER_MAXX)
  130.             player->lx += xytable[PLAYER_SPEED][0].x;
  131.         if (player->bank < 0) {
  132.             player->bank = 0;
  133.         } else {
  134.             if (player->bank < PLAYER_BANK2)
  135.                 player->bank++;
  136.         }
  137.         break;
  138.  
  139.     default:        /* それ以外 */
  140.         /* 自機の傾きを元に戻す処理 */
  141.         if (player->bank != 0) {
  142.             if (player->bank > 0)
  143.                 player->bank--;
  144.             else
  145.                 player->bank++;
  146.         }
  147.         break;
  148.     }
  149.  
  150.     /* 自機の傾き (player->bank) から自機の複合スプライトNo.を求める */
  151.     if (player->bank == 0) {
  152.         player->pt = obj_player + PLAYER_PT_CENTER;
  153.     } else {
  154.         if (player->bank > 0) {
  155.             if (player->bank < PLAYER_BANK1)
  156.                 player->pt = obj_player + PLAYER_PT_LEFT1;
  157.             else
  158.                 player->pt = obj_player + PLAYER_PT_LEFT2;
  159.         } else {
  160.             if (player->bank > -PLAYER_BANK1)
  161.                 player->pt = obj_player + PLAYER_PT_RIGHT1;
  162.             else
  163.                 player->pt = obj_player + PLAYER_PT_RIGHT2;
  164.         }
  165.     }
  166.     player->x = player->lx / 65536;
  167.     player->y = player->ly / 65536;
  168.  
  169.     /* 各種キー入力 */
  170.     if ((j & 0b1111) == 0) {    /* [SELECT]+[START] */
  171.         player->game_over = GAME_ABORT;
  172.         return;
  173.     }
  174.     if (_iocs_bitsns (0x0c) & 0b10) {
  175.         /* [BREAK] */
  176.         while (_iocs_bitsns (0x0c) & 0b10);
  177.         player->game_over = GAME_ABORT;
  178.         return;
  179.     }
  180.     /* ポーズ処理 */
  181.     if ((_iocs_bitsns (0x00) & 0b10)    /* [ESC] */
  182.         ||((j & 0b1100) == 0)) {    /* ゲーム中に [START] */
  183.         pause_flag = !0;
  184.         while ((_iocs_bitsns (0x00) & 0b10) || ((_iocs_joyget (0) & 0b1100) == 0));
  185.         while ((!(_iocs_bitsns (0x00) & 0b10)) && (!((_iocs_joyget (0) & 0b1100) == 0)));
  186.         while ((_iocs_bitsns (0x00) & 0b10) || ((_iocs_joyget (0) & 0b1100) == 0));
  187.         pause_flag = 0;
  188.     }
  189.     /* 無敵状態の処理 */
  190.     player->info = PLAYER_PALET | PRIORITY_PLAYER;
  191.     if (player->muteki) {
  192.         player->muteki--;
  193.         player->flash++;
  194.         if (player->muteki > 55) {
  195.             /* バリアが沢山残っているので速いフラッシュ */
  196.             if (player->flash > 1) {
  197.                 player->info = PLAYER_PALET_FLASH | PRIORITY_PLAYER;
  198.                 player->flash = 0;
  199.             }
  200.         } else {
  201.             /* バリアが少ししかないので遅いフラッシュ */
  202.             if (player->flash > 5)
  203.                 player->info = PLAYER_PALET_FLASH | PRIORITY_PLAYER;
  204.             if (player->flash > 10)
  205.                 player->flash = 0;
  206.         }
  207.     }
  208.     xobj_set_st (player);    /* 自機を表示 */
  209.  
  210.     /* コアの表示 */
  211.     player->core_x = player->x - 8;
  212.     player->core_y = player->y - 8;
  213.     xsp_set_st (&(player->core_x));
  214. }
  215.  
  216.  
  217. /* 自機が死んだ時の移動処理 */
  218. static void PlayerMoveDead (void)
  219. {
  220.     player->x = player->lx / 65536;
  221.     player->y = player->ly / 65536;
  222.  
  223.     /* 自機の傾きを元に戻す処理 */
  224.     if (player->bank != 0) {
  225.         if (player->bank > 0)
  226.             player->bank--;
  227.         else
  228.             player->bank++;
  229.     }
  230.     /* 自機の傾き (player->bank) から自機の複合スプライトNo.を求める */
  231.     if (player->bank == 0) {
  232.         player->pt = obj_player + PLAYER_PT_CENTER;
  233.     } else {
  234.         if (player->bank > 0) {
  235.             if (player->bank < PLAYER_BANK1)
  236.                 player->pt = obj_player + PLAYER_PT_LEFT1;
  237.             else
  238.                 player->pt = obj_player + PLAYER_PT_LEFT2;
  239.         } else {
  240.             if (player->bank > -PLAYER_BANK1)
  241.                 player->pt = obj_player + PLAYER_PT_RIGHT1;
  242.             else
  243.                 player->pt = obj_player + PLAYER_PT_RIGHT2;
  244.         }
  245.     }
  246.  
  247.     player->info = PLAYER_PALET | PRIORITY_PLAYER;
  248.     switch (player->counter++) {
  249.     case 0:
  250.         /* 今死んだところなら爆発パターンを出す */
  251.         EffectAlloc (EFFECT_EXPLPLAYER, 0, player->x, player->y);    /* 爆発パターンを出現させる */
  252.         SoundSetSE (SE_PLAYER_EXPL);    /* プレイヤーの爆発音 */
  253.         break;
  254.     case 8 * 1:
  255.     case 8 * 2:
  256.     case 8 * 3:
  257.     case 8 * 4:
  258.     case 8 * 5:
  259.         {
  260.             signed short x, y;
  261.             x = rndtable[(player->counter) & 0xff ^ 0x55] - 128;
  262.             y = rndtable[(player->counter + 1) & 0xff ^ 0xaa] - 128;
  263.             /* player->counter は乱数の種として使用しています */
  264.             EffectAlloc (EFFECT_EXPLPLAYER, 0, player->x + x / 8, player->y + y / 8);
  265.             SoundSetSE (SE_PLAYER_EXPL);    /* プレイヤーの爆発音 */
  266.         }
  267.         break;
  268.  
  269.     case 8 * 7:
  270.         /* 最後の「どっかーん」 */
  271.         EffectAlloc (EFFECT_EXPLPLAYER, 0, player->x, player->y);
  272.         SoundSetSE (SE_EXPL_L);
  273.         player->x = 256 + 32;
  274.         player->y = 256 + 32;
  275.         break;
  276.     case 8 * 12:
  277.         /* 座標を初期化 */
  278.         player->lx = PLAYER_START_X * 65536;
  279.         player->ly = PLAYER_START_Y * 65536;
  280.         player->status = PLAYER_STATUS_APPEAR;    /* 出現状態へ */
  281.         player->counter = 0;
  282.         player->rest--;
  283.         if (player->rest <= 0) {
  284.             player->game_over = GAME_OVER;
  285.         } else {
  286.             if (!eshot_erase)
  287.                 eshot_erase = ESHOT_ERASE;    /* 弾消し */
  288.         }
  289.         DispRest ();    /* 残機数表示 */
  290.         break;
  291.  
  292.     default:
  293.         if (player->counter < 55) {
  294.             xobj_set_st (player);    /* 自機を表示 */
  295.             /* コアの表示 */
  296.             player->core_x = player->x - 8;
  297.             player->core_y = player->y - 8;
  298.             xsp_set_st (&(player->core_x));
  299.         }
  300.         break;
  301.     }
  302. }
  303.  
  304.  
  305.  
  306. /* 自機が死んだ後の登場処理 */
  307. static void PlayerMoveAppear (void)
  308. {
  309.     player->bank = 0;
  310.     player->pt = obj_player + PLAYER_PT_CENTER;
  311.     player->ly -= (4 * 65536);
  312.  
  313.     player->x = player->lx / 65536;
  314.     player->y = player->ly / 65536;
  315.  
  316.     /* 自機がある程度上まで進んだら通常状態へ */
  317.     if (player->y < 160) {
  318.         player->status = PLAYER_STATUS_ALIVE;
  319.         player->muteki = TIME_MUTEKI;
  320.     }
  321.     player->info = PLAYER_PALET | PRIORITY_PLAYER;
  322.     if (player->flash++ > 1) {
  323.         player->info = PLAYER_PALET_FLASH | PRIORITY_PLAYER;
  324.         player->flash = 0;
  325.     }
  326.     xobj_set_st (player);    /* 自機を表示 */
  327.     /* コアの表示 */
  328.     player->core_x = player->x - 8;
  329.     player->core_y = player->y - 8;
  330.     xsp_set_st (&(player->core_x));
  331. }
  332.  
  333.  
  334.  
  335. /* ボスを倒した後の移動処理 */
  336. static void PlayerMoveComplete (void)
  337. {
  338.     /* 自機の傾きを元に戻す処理 */
  339.     if (player->bank != 0) {
  340.         if (player->bank > 0)
  341.             player->bank--;
  342.         else
  343.             player->bank++;
  344.     }
  345.     /* 自機の傾き (player->bank) から自機の複合スプライトNo.を求める */
  346.     if (player->bank == 0) {
  347.         player->pt = obj_player + PLAYER_PT_CENTER;
  348.     } else {
  349.         if (player->bank > 0) {
  350.             if (player->bank < PLAYER_BANK1)
  351.                 player->pt = obj_player + PLAYER_PT_LEFT1;
  352.             else
  353.                 player->pt = obj_player + PLAYER_PT_LEFT2;
  354.         } else {
  355.             if (player->bank > -PLAYER_BANK1)
  356.                 player->pt = obj_player + PLAYER_PT_RIGHT1;
  357.             else
  358.                 player->pt = obj_player + PLAYER_PT_RIGHT2;
  359.         }
  360.     }
  361.  
  362.     player->info = PLAYER_PALET | PRIORITY_PLAYER;
  363.  
  364.     player->ly -= (4 * 65536);
  365.     player->x = player->lx / 65536;
  366.     player->y = player->ly / 65536;
  367.     xobj_set_st (player);    /* 自機を表示 */
  368.     if (player->y < -32)
  369.         player->game_over = GAME_COMPLETE2;    /* ゲーム終了 */
  370.  
  371.     /* コアの表示 */
  372.     player->core_x = player->x - 8;
  373.     player->core_y = player->y - 8;
  374.     xsp_set_st (&(player->core_x));
  375. }
  376.  
  377.  
  378.  
  379. /* 垂直同期ごとに呼ばれる */
  380. void PlayerMove (void)
  381. {
  382.     if ((player->game_over == GAME_COMPLETE)
  383.         && (player->status == PLAYER_STATUS_ALIVE))
  384.         player->status = PLAYER_STATUS_COMPLETE;
  385.  
  386.     switch (player->status) {
  387.     case PLAYER_STATUS_ALIVE:
  388.         PlayerMoveAlive ();
  389.         break;
  390.     case PLAYER_STATUS_DEAD:
  391.         PlayerMoveDead ();
  392.         break;
  393.     case PLAYER_STATUS_APPEAR:
  394.         PlayerMoveAppear ();
  395.         break;
  396.     case PLAYER_STATUS_COMPLETE:
  397.         PlayerMoveComplete ();
  398.         break;
  399.     }
  400. }
  401.